package me.jessyan.mvparms.demo.mvp.ui.view;

import android.graphics.Canvas;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.MotionEvent;



import java.util.List;

import me.jessyan.mvparms.demo.mvp.model.entity.Discover;
import me.jessyan.mvparms.demo.mvp.ui.adapter.DiscoverAdapter;

/**
 * The author: Zhao X.H.
 * Creation time: 2018/5/8 ${time}
 */

public class SwipeCardCallBack extends ItemTouchHelper.SimpleCallback implements RecyclerView.OnItemTouchListener {
    private SwipeCardListener mListener;
    public SwipeCardCallBack(int dragDirs, int swipeDirs,SwipeCardListener mListener) {
        super(dragDirs, swipeDirs);
        this.mListener = mListener;
    }

    public SwipeCardCallBack(List<Discover> mData, DiscoverAdapter mAdapter, RecyclerView mDiscover, SwipeCardListener mListener) {
        /*
        * 即我们对哪些方向操作关心。如果我们关心用户向上拖动，可以将
         填充swipeDirs参数为LEFT | RIGHT 。0表示从不关心。
        * */
        super(0,
                ItemTouchHelper.LEFT | ItemTouchHelper.UP |
                        ItemTouchHelper.RIGHT | ItemTouchHelper.DOWN
        );
        this.mListener = mListener;
    }
    @Override
    public boolean onMove(RecyclerView recyclerView,
                          RecyclerView.ViewHolder viewHolder,
                          RecyclerView.ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder,
                         int direction) {
        mListener.onSwiped(viewHolder,direction);
    }

    @Override
    public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
        super.onChildDraw(c, recyclerView, viewHolder, dX,
                dY, actionState, isCurrentlyActive);

        mListener.onChildDraw(c,recyclerView,viewHolder,dX,dY,actionState,isCurrentlyActive);
    }

    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
        return true;
    }

    @Override
    public void onTouchEvent(RecyclerView rv, MotionEvent e) {

    }

    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

    }

    public interface SwipeCardListener{
        void onSwiped(RecyclerView.ViewHolder viewHolder, int direction);
        void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive);
    }
}
